$(function(){
    var take = $.cookie("token");
    $.get("http://47.104.244.134:8080/cartlist.do", {"token":take}, function (data) {
           var str = ""
           for (var i in data) {
                          //展示商品的所有信息
            str+="<li data-gid="+data[i].gid+" data-id="+data[i].id+"><h2>"+data[i].goods.name+"</h2><img src ='"+data[i].goods.picurl+"'/><p>"+data[i].goods.price+"</p><em class='qwem2'>-</em><i id='pre'>"+data[i].count+"</i><em class='qwem3'>+</em><input class='btn' type='button' data-id='"+data[i].id+"' value='清除此购物'></li>"
               // console.log(data[i].goods.name,data[i].goods.picurl,data[i].goods.price)
    }  
         //   console.log(data)
        $(".content").html(str);
    
    //删除购物车
    $(document).on("click","input",function(){
        var goodsId = this.getAttribute("data-id");
        $.get("http://47.104.244.134:8080/cartupdate.do",{"token":take,"id":goodsId,"gid":goodsId,"num":0 }, 
           function (data){
               //打印id
            // console.log(goodsId) 
        }) ;
        //重新加载页面
        window.location.href = "car.html";
      }); 
         
 //给商品添加详情信息
 $(".content").on("click","em",function(){
    //拿到商品的id
    var id = $(this).parent().attr("data-id");
    var gid = $(this).parent().attr("data-gid");
    var take = $.cookie("token");
        $.get("http://47.104.244.134:8080/cartupdate.do",{"token":take,"id":id,"gid":gid,"num":-1}, 
        function (data){
            console.log(data);
        }); 
        var pre = $(this).next().text();
         console.log(add(pre));
        //$(this).next().text().html(pre)
    });   
});


}) 